#!/usr/bin/env ruby

require 'rubygems'
require 'faster_csv'

require 'util'

CLUSTER_SIZE = 5

points = []

FasterCSV.foreach("clusters.csv", :converters => :float) do |row|
  points << Point.new(row[0], row[1])
end

# For each point find its closest N neighbors
clusters = []
points.each do |point|
  clusters << points.map {|p| p.distance(point)}.sort.slice(1, CLUSTER_SIZE)
end

avg = clusters.map {|c| c.avg}.avg
std_dev = clusters.map {|c| c.avg}.std_dev

puts "Inter cluster data where cluster size = #{CLUSTER_SIZE}"
puts "Average Distance:   #{avg}"
puts "Standard Deviation: #{std_dev}"
